var express = require('express');
var router = express.Router();
var { rukuModel } = require('../module/ruku')

// 待入库列表
router.get('/list', async (req, res) => {
    // let page = req.query.page
    // let pagesize = req.query.pagesize
    let dataList = await rukuModel.find()
    // let total = dataList.length
    // dataList = dataList.slice((page - 1) * pagesize, pagesize * page)
    res.send({
        dataList
        // , total
    })
});

router.post('/addaddlist', async (req, res) => {
    let body = req.body
    // console.log(body);
    let dataList = await rukuModel.create(body)
    // console.log(dataList);
    res.send({ dataList, msg: '添加成功', code: 200 },)
});
router.put('/editaddlist', async (req, res) => {
    let _id = req.body.id
    let body = req.body
    let dataList = await rukuModel.updateOne({ _id: _id }, { $set: body })
    // console.log(dataList);
    res.send({ dataList, msg: '修改成功', code: 200 },)
});

router.delete('/del/:id', async (req, res) => {
    let _id = req.params.id
    await rukuModel.deleteOne({ _id: _id })
    res.send({ code: 200, msg: '删除成功' })
})

module.exports = router;